home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
glass
/
glass.lha
/
GLASS
/
glassme
/
gme06
< prev
next >
Wrap
Text File
|
1991-02-19
|
5KB
|
113 lines
%TEX
\subsubsection{Fill in applications with right number of parameters}
Fill in tries to match the actual arguments of a macro application
to the formal arguments of a body of the macro definition.
When such a body is found a replace list is built and the body is copied with
formal constructors appearing as a key in the replace list replaced by the value of that key.\\
So the triple $(\lambda,\kappa,\varphi)$ expresses that in the replace list
$\lambda$ the formal constructor $\kappa$ should be replaced by the actual
constructor $\varphi$.
Glammar offers the designer builtins to store and retrieve such items easely.
The builtin \verb+ add to(>list,>key,>val)+ stores an item.
\verb+ lookup(>list,>key,val>)+ retrieves the value of an item if it is
in the list; otherwise it fails.
Unique list names can be generated using the builtin \verb+ some name(name>)+.
%
fill in (>empty,>x,empty>): ->, fail;
fill in (>fp and body*_,>actual args,matched body>):
some name (replace list>),
replace list (>replace list,>actual args,>fp and body,body>), ->,
copy meta ds (>replace list,>body, matched body>),
trans val (>matched body, >matched body,>empty);
fill in (>fp and body*r,>actual args,matched body>):
fill in (>r,>actual args,matched body>).
%TEX
\subsubsection{Copy data structure with replace list.}
Here we copy a formal macro body taken into account
that the formal parameters should be replaced by actual ones
The formal names that should be replaced are stored in a
replace list which contains triples like {\tt (replace list, formal name,
actual ds pointer)}.
If a formal name {\tt x} must be replaced by an actual name {\tt y}
its name occurs in
in the replace list as a key .
An instance of this triple could {\tt (aY, x, <NODE y>)}.
{\tt aY} is the value of replace list and {\tt <NODE y>} the data structure
representing {\tt VSym "y"}
Then we replace the data structure part {\tt FnSym "x"} to the node {\tt <NODE y>}
which we retrieved as the value of the triple.
%
copy meta ds (>replace list,>node, nnode>):
where (>node,DefVal*valorig*defval*body> ),
where (>body, VType*vttype* vMacAlts V vMacLambda*_>), ->,
copy local mac or def (>replace list,>valorig,>defval,>body,
>vMacAlts V vMacLambda,nnode>);
copy meta ds (>replace list,>FCSym*STRING* symbol,FCSym*STRING*new name>):->,
some name (uniq>),
where (>symbol+"_"+uniq, new name>),
where (>VSym*org*STRING*new name, new node>),
where (>TUPLE*file el*line el, org>),
where ( >STRING * "local_macroexp_name", file el>),
where (>I NUM *"0",line el>),
add to (>replace list,>symbol,>new node);
copy meta ds (>replace list,>VSym*org*STRING* symbol,new node>):
lookup (>replace list,>symbol, new node>),->;
copy meta ds (>replace list,>VSym*org*STRING* symbol,new node>):
excludes (>symbol,>"Def"),
excludes (>symbol,>"Mac"),
excludes (>symbol,>"Atom"),
excludes (>symbol,>FORMAL PAR),
excludes (>symbol,>"Aux"), ->,
some name (uniq>),
where (>symbol+"_"+uniq, new name>),
where (>VSym*org*STRING*new name, new node>),
add to (>replace list,>symbol,>new node);
copy meta ds (>replace list,>node, node>):
where (>node,VSym*org*STRING*name>), ->;
copy meta ds (>replace list,>x*y, new x * new y>): ->,
copy meta ds (>replace list,>x ,new x>),
copy meta ds (>replace list,>y ,new y>);
copy meta ds (>replace list,>x, x >):.
copy local mac or def (>replace list,>valorig,>defval,>body,
>VMacAlts,nnode>):-> ,
where (>defval, STRING*symbol>),
where (>symbol+"_"+replace list, new name>),
where ( >STRING*new name, ndefval>),
where (>VSym*valorig*ndefval, new symbol node>),
add to (>replace list,>symbol,>new symbol node),
copy meta ds (>replace list,>body,nbody>),
where (> DefVal*valorig*ndefval*nbody, nnode>),
add to (>new name,>"Mac",>nnode);
copy local mac or def (>replace list,>valorig,>defval,>body,
>VMacLambda,nnode>):->,
where (>defval, STRING*symbol>),
where (>symbol+"_"+replace list, new name>),
where ( >STRING*new name, ndefval>),
where (>VSym*valorig*ndefval, new symbol node>),
add to (>replace list,>symbol,>new symbol node),
copy meta ds (>replace list,>body,nbody>),
where (> DefVal*valorig*ndefval*nbody, nnode>),
add to (>new name,>"Def",>nnode);
copy local mac or def (>replace list,>valorig,>defval,>body,>V type,nnode>):
copy meta ds (>replace list,>body,nbody>),
where (> DefVal*valorig*defval*nbody, nnode>).
trace list (>a*empty):
type out (>a+"."+nlcr), ->;
trace list (>a*b):
type out (>a+","+nlcr),
trace list (>b),->;
trace list (>a):
type out (>a+"?"+nlcr).